package cn.com.dycc.party_work.transfer.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.party_work.transfer.entity.TransferInfo;
import cn.com.dycc.party_work.transfer.entity.TransferParam;
import cn.com.dycc.party_work.transfer.param.FindTransferParam;
import cn.com.dycc.party_work.transfer.service.TransferNotFoundException;
import cn.com.dycc.party_work.transfer.service.TransferService;
import cn.com.dycc.util.JsonObjectResult;

/**
 * 
 * Description: 申请入党控制层
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年6月21日 上午8:54:05.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/transfer")
public class TransferController extends BaseController {
	
	@Resource
	private TransferService transferService;

	@RequestMapping("/add.do")	
	@ResponseBody
	public JsonObjectResult addTransfer(TransferParam param,HttpServletRequest req){
		int n = transferService.addTransfer(param, req);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/delete.do")	
	@ResponseBody
	public JsonObjectResult deleteTransfer(String transfer_ids[],HttpServletRequest req){
		int n = transferService.deleteTransfer(transfer_ids, req);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/update.do")	
	@ResponseBody
	public JsonObjectResult updateTransfer(TransferParam param, HttpServletRequest req){
		int n = transferService.updateTransfer(param, req);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/find.do")	
	@ResponseBody
	public JsonObjectResult findTransfer(FindTransferParam param, HttpServletRequest req){
		String count = transferService.findTransferCountByParam(param, req);
		List<TransferInfo> list = transferService.findTransferByParam(param, req);
		return new JsonObjectResult(count,list);
	}
	
	
	@ExceptionHandler(TransferNotFoundException.class)
	@ResponseBody
	public JsonObjectResult applyException(TransferNotFoundException e){
		e.printStackTrace();
		return new JsonObjectResult(45,e);
	}
}
